require(['./config'], () => {
  require(['header', 'footer'], () => {
    class Login {
      constructor() {
        this.register();
      }

      register() {
        $('#okBtn').on('click', () => {
          const name = $('#username').val();
          const pwd = $('#userpwd').val();
          if (name.length < 11) {
            alert('手机号码格式错误，请重新输入！')
            $('#username').val('');
            $('#userpwd').val('');
          } else if (pwd.length < 8) {
            alert('密码长度不能小于8位错误，请重新输入！')
            $('#userpwd').val('');
          } else {
            let obj = { name, pwd };
            let userList = localStorage.getItem('userList');
            if (userList) {
              userList = JSON.parse(userList);
              let isExist = userList.some((user) => user.name === name);
              if (isExist) {
                alert('该用户名已存在，请重新输入!');
                $('#username').val('');
                $('#userpwd').val('');
              } else {
                userList.push(obj);
                localStorage.setItem('userList', JSON.stringify(userList));
                alert('注册成功，立即登录')
                window.open('/html/login.html', '_self');
              }
            } else {
              let arr = [obj];
              localStorage.setItem('userList', JSON.stringify(arr));
              alert('注册成功，立即登录')
              window.open('/html/login.html', '_self');
            }
          }

        })
      }
    }
    new Login()
  })
})